# list, tuple, str, set, dict
# 列表: list
# name_list = ['itheima', 'itcast', 'python']
# print(name_list)
# print(type(name_list))
# print(name_list[0])
#
# my_list = [[1, 2, 3], [4, 5, 6]]
# print(my_list)
# print(type(my_list))
# print(my_list[0][3])

# index of list
# 从左向右从0开始，从右向左从-1开始
# name_list = ['itheima', 'itcast', 'python']
# print(name_list[0])
# print(name_list[1])
# print(name_list[2])
# print(name_list[-1])  # python
# print(name_list[-2])  # itcast
# print(name_list[-3])  # itheima

# list 常用操作
# name = ['itheima', 'itcast', 'python']
# index = name.index('itcast')
# print(index)
# index = name.index('itcast1')  # 'itcast1' is not in list
# print(index)

# 修改索引指定位置的值
# name[1] = 'itit'
# print(name)

# insert 指定位置插入指定元素值(前面插入)
# name.insert(0,'python1')
# print(name)

# append 追加指定元素到列表的尾部
# name.append('python2')
# print(name)

# extend， 追加一批元素到列表的尾部,参数是其他数据容器
# name_list = [1, 'python3']
# name.extend(name_list)
# print(name)

# 删除元素
# 1. del 列表[下标]
# 2. 列表.pop(下标)
# name = ['itheima', 'itcast', 'python']
# print(name)
# del name[2]
# print(name)
# pop可以弹出指定元素，并返回
# element = name.pop(0)
# print(element)
# print(name)

# 删除指定内容的元素, remove方法,从前到后搜索该元素，并删除遇到的第一个它
# my_list = [1, 2, 3, 2, 4, 5]
# my_list.remove(2)
# print(my_list)

#  清空列表(删除所有元素)
# my_list.clear()
# print(my_list)

# 统计某元素的数量
# my_list = [1, 2, 3, 2, 4, 5, 2]
# count = my_list.count(2)
# print(count)

# 统计列表中总共有多少元素
# count_all = len(my_list)
# print("总共有%s个列表元素" % count_all)


# 列表的案例
stu_age = [21, 25, 21, 23, 22, 20]

stu_age.append(31)
print(stu_age)
new_list = [29, 33, 30]
stu_age.extend(new_list)
print(stu_age)
first_element = stu_age[0]
print(first_element)
last_ele = stu_age[-1]
print(last_ele)
index = stu_age.index(31)
print(index)
print(stu_age)